import csv
import sqlite3

connection = sqlite3.connect('../db.sqlite3')
cursor = connection.cursor()

create_table = '''
create table data_NoteBook
(
    Name text not null,
    PID text not null,
    NotebookID text not null,
    Position text not null,
    Price integer,
    CPU_Name text,
    CPU_Frequency text,
    CPU_MAX_Frequency text,
    CPU_CT text,
    CPU_L3Cache text,
    CPU_CoreName text,
    CPU_Process text,
    CPU_Power text,
    RAM_Capacity text,
    RAM_Type text,
    ROM_Capacity text,
    ROM_Type text,
    Display_Touch text,
    Display_Type text,
    Display_Size text,
    Display_Scale text,
    Display_Resolution text,
    Display_Brightness text,
    Display_Ratio text,
    Display_Technology text,
    Display_RefreshRate text,
    Display_Gamut text,
    GPU_Name text,
    GPU_Capacity text,
    GPU_Type text,
    GPU_BW text,
    GPU_MAX_Power text,
    GPU_Dedicated text,
    Loudspeaker text,
    Microphone text,
    Wireless text,
    Wired_Network text,
    Bluetooth text,
    Data_Interface text,
    Video_Interface text,
    Audio_Interface text,
    Other_Interface text,
    Battery_Type text,
    Power_Adapter text,
    Weight text,
    Length text,
    Width text,
    Thickness text,
    Material text,
    Color text,
    constraint notebook_pk
        primary key (Name,PID,NotebookID,Position)
);

'''

cursor.execute(create_table)
file = open('../GetInfo/Details/NotebookInfo.csv', encoding='utf-8')
contents = csv.reader(file)
insert_records = "INSERT INTO data_NoteBook (Name,PID,NotebookID,Position,Price,CPU_Name,CPU_Frequency,CPU_MAX_Frequency,CPU_CT,CPU_L3Cache,CPU_CoreName,CPU_Process,CPU_Power,RAM_Capacity,RAM_Type,ROM_Capacity,ROM_Type,Display_Touch,Display_Type,Display_Size,Display_Scale,Display_Resolution,Display_Brightness,Display_Ratio,Display_Technology,Display_RefreshRate,Display_Gamut,GPU_Name,GPU_Capacity,GPU_Type,GPU_BW,GPU_MAX_Power,GPU_Dedicated,Loudspeaker,Microphone,Wireless,Wired_Network,Bluetooth,Data_Interface,Video_Interface,Audio_Interface,Other_Interface,Battery_Type,Power_Adapter,Weight,Length,Width,Thickness,Material,Color) " \
                 "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

cursor.executemany(insert_records, contents)
select_all = "SELECT * FROM data_NoteBook"
rows = cursor.execute(select_all).fetchall()
for r in rows:
    print(r)

# Committing the changes
connection.commit()
connection.close()
